﻿// OperatorListView.cpp: 实现文件
//

#include "stdafx.h"
#include "zChecker.h"
#include "OperatorListView.h"


// COperatorListView

IMPLEMENT_DYNCREATE(COperatorListView, CListView)

COperatorListView::COperatorListView()
{

}

COperatorListView::~COperatorListView()
{
}

BEGIN_MESSAGE_MAP(COperatorListView, CListView)
	ON_WM_CREATE()
END_MESSAGE_MAP()


// COperatorListView 诊断

#ifdef _DEBUG
void COperatorListView::AssertValid() const
{
	CListView::AssertValid();
}

#ifndef _WIN32_WCE
void COperatorListView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif
#endif //_DEBUG


// COperatorListView 消息处理程序


int COperatorListView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CListView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  在此添加您专用的创建代码
	CListCtrl& list = GetListCtrl();

	list.ModifyStyle(0, LVS_REPORT | LVS_SINGLESEL);
	list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_AUTOSIZECOLUMNS);

	list.InsertColumn(0, "算子名称", LVCFMT_LEFT, 150);
	list.InsertColumn(1, "所属模块", LVCFMT_LEFT, 150);
	list.InsertColumn(2, "开发者", LVCFMT_LEFT, 150);
	list.InsertColumn(3, "算子说明", LVCFMT_LEFT, 300);

	return 0;
}
 
void COperatorListView::Populate()
{
	CListCtrl& list = GetListCtrl();
	list.DeleteAllItems();

	ck::Module* pModule = NULL;
	ck::ModuleManager* pModManager = ck::ModuleManager::GetInstance();

	int nModCout = pModManager->GetCount();
	for (int i = 0; i < nModCout; i++)
	{
		pModule = pModManager->GetModule(i);
		
		Populate(pModule);
	}
}

void COperatorListView::Populate(ck::Module* pModule)
{
	CListCtrl& list = GetListCtrl();
	list.DeleteAllItems();

	ck::Operator* pOperator = NULL;

	int nOprCount = pModule->GetOperatorCount();
	for (int j = 0; j < nOprCount; j++)
	{
		pOperator = pModule->GetOperator(j);

		int nItem = list.InsertItem(list.GetItemCount(), pOperator->GetName());
		list.SetItemText(nItem, 1, pOperator->GetModuleName());
		list.SetItemText(nItem, 2, pModule->GetDeveloper());
		list.SetItemText(nItem, 3, pOperator->GetDescription());
	}
}

void COperatorListView::Populate(ck::Operator* pOperator)
{
	CListCtrl& list = GetListCtrl();
	list.DeleteAllItems();
}